﻿using MediatR;
using S.Authorization.Domain.Model.Authority;
using S.Authorization.Infrastructure;
using S.Authorization.Infrastructure.Interface.Menu;
using S.Authorization.Read.API.Dto;
using static S.Authorization.Read.API.Application.Command.MenuCommand.MenuCountCommand;

namespace S.Authorization.Read.API.Application.CommandHandlers.MenuCommandHandler
{
    /// <summary>
    /// 仓储实现类—常用功能
    /// </summary>
    public class MenuCountCommandHandler : IRequestHandler<GetMenuCountCommand, List<MenuCountDto>>
    {

        private readonly DbHelper db;

        public MenuCountCommandHandler(DbHelper _db)
        {
            this.db = _db;
        }
        /// <summary>
        /// 显示常用功能信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<List<MenuCountDto>> Handle(GetMenuCountCommand request, CancellationToken cancellationToken)
        {
            string sql = @"SELECT top 5 b.MenuName,a.Path,a.Logo FROM [dbo].[MenuListCount] a 
                        join [dbo].[MenuList] b on a.MenuId = b.MenuId 
                        where a.MenuId != 98
                        ORDER BY Count DESC ";
            var list = await db.GetListDataBySql<MenuCountDto>(sql);
            return list;
        }
    }
}
